<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>商品导购</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
</head><body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form class="layui-form" <c:if test="${!empty subjectId}">action="${ctx}/mall/showgoods/list.do"</c:if>
                    <c:if test="${!empty templateId}">action="${ctx}/mall/showtemplategoods/list.do"</c:if> id="myForm" method="get">
                <input type="hidden" name="pageNo" id="pageNo"/>
                <input type="hidden" name="categoryId" id="categoryId" value="${mallShowGoodsWithAuthor.categoryId}"/>
                <input type="hidden" name="subjectId" id="subjectId" value="${subjectId}"/>
                <input type="hidden" name="templateId" id="templateId" value="${templateId}"/>
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline"><label class="search-form-lable">商品名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" autocomplete="off" class="layui-input"
                                           value="${mallShowGoodsWithAuthor.name}" placeholder="请输入查询商品名称"/>
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">发布者</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="memberName" autocomplete="off" class="layui-input"
                                           value="${mallShowGoodsWithAuthor.memberName}" placeholder="请输入查询商品发布者"/>
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger"
                                       href="javascript:submitFunction('#myForm')">查询</a>
                                    <a class="layui-btn layui-btn-normal"
                                       href="javascript:resetFunction('#myForm')">重置</a>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">发布时间</label>
                                <div class="check-btn-inner" id="timeType">
                                    <a id="all" href="javascript:void(0);"
                                       onclick="setTimeType($(this),0,'#myForm')" ${empty mallShowGoodsWithAuthor.timeType || mallShowGoodsWithAuthor.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),1,'#myForm')" ${mallShowGoodsWithAuthor.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),2,'#myForm')" ${mallShowGoodsWithAuthor.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),3,'#myForm')" ${mallShowGoodsWithAuthor.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                    <input type="hidden" name="timeType" value="${mallShowGoodsWithAuthor.timeType}"/>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createStart"
                                               value="${mallShowGoodsWithAuthor.createStart}" placeholder="开始日"
                                           />
                                    </div>
                                    -
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createEnd"
                                               value="${mallShowGoodsWithAuthor.createEnd}" placeholder="截止日"
                                          />
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="c-time-list-content">
                <ul id="view">
                    <c:if test="${page.totalCount == 0}">
                        <div class="f16 tc mt15">还没有数据，请点击右上角的“发布商品”</div>
                    </c:if>
                    <c:forEach var="goods" items="${goodsList}" varStatus="status">
                        <li>
                            <c:if test="${!empty subjectId}">
                                <div class="detail-content">
                                    <a href="${ctx}/mall/showgoods/showgoodform.do?id=${goods.id}&subjectId=${subjectId}&categoryId=${categoryId}"
                                       target="_self" class="act-logo common-img"

                                    >
                                        <img src="<c:if test="${goods.pic != null}">${goods.pic}?imageMogr2/auto-orient/crop/200x150</c:if>" alt="" onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                                    </a>
                                    <div class="detail">
                                        <div class="act-title">
                                            <a title="${goods.name}"
                                               href="${ctx}/mall/showgoods/showgoodform.do?id=${goods.id}&subjectId=${subjectId}&categoryId=${categoryId}"
                                               target="_self" class="title f18 ell db">${goods.name}</a>
                                        </div>
                                        <div>
                                            <p class="act-price">
                                                发布时间：
                                                <fmt:formatDate value="${goods.createDate}" pattern="yyyy-MM-dd HH:mm"/>
                                            </p>
                                            <p class="act-price">
                                                <span>发布者：<b class="active-red">${goods.memberName}</b></span>
                                            </p>
                                            <p class="act-price">
                                                <span>说明：<b>${goods.remarks}</b></span>
                                            </p>
                                        </div>
                                        <div class="opts-btns tb-opts" style="width:475px">
                                            <div class="comm-opts">
                                                <c:set var="index" value="${(status.index + 1) + (page.page - 1) * page.limit}" />
                                                <c:if test="${index > 1}">
                                                    <a href="javascript:goodsUpdateSort('up', '${goods.id}','${page}','${categoryId}')"><i class="iconfont icon-top1"></i> 向上</a>
                                                </c:if>

                                                <c:if test="${index < page.totalCount}">
                                                    <a href="javascript:goodsUpdateSort('down', '${goods.id}','${page}','${categoryId}')"><i class="iconfont icon-down"></i> 向下</a>
                                                </c:if>
                                                <a href="${ctx}/mall/showgoods/showgoodform.do?id=${goods.id}&subjectId=${subjectId}&categoryId=${categoryId}">
                                                    <i class="iconfont icon-edit btn-icon"></i> 编辑</a>
                                                <a href="javascript:txz.deleteObject('确定要删除该商品？','${ctx}/mall/showgoods/delete.do?id=${goods.id}')">
                                                    <i class="iconfont icon-delete btn-icon"></i> 删除
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </c:if>
                            <c:if test="${!empty templateId}">
                                <div class="detail-content">
                                    <a href="${ctx}/mall/showtemplategoods/showgoodform.do?id=${goods.id}&templateId=${templateId}&categoryId=${categoryId}"
                                       target="_self" class="act-logo common-img"

                                    >
                                        <img src="<c:if test="${ goods.pic!= null}">${goods.pic}?imageMogr2/auto-orient/crop/200x150</c:if>" alt="" onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                                    </a>
                                    <div class="detail">
                                        <div class="act-title">
                                            <a title="${goods.name}"
                                               href="${ctx}/mall/showtemplategoods/showgoodform.do?id=${goods.id}&templateId=${templateId}&categoryId=${categoryId}"
                                               target="_self" class="title f18 ell db">${goods.name}</a>
                                        </div>
                                        <div>
                                            <p class="act-price">
                                                发布时间：
                                                <fmt:formatDate value="${goods.createDate}" pattern="yyyy-MM-dd HH:mm"/>
                                            </p>
                                            <p class="act-price">
                                                <span>发布者：<b class="active-red">${goods.memberName}</b></span>
                                            </p>
                                            <p class="act-price">
                                                <span>说明：<b>${goods.remarks}</b></span>
                                            </p>
                                        </div>
                                        <div class="opts-btns tb-opts" style="width:475px">
                                            <div class="comm-opts">
                                                <c:set var="index" value="${(status.index + 1) + (page.page - 1) * page.limit}" />
                                                <c:if test="${index > 1}">
                                                    <a href="javascript:goodsUpdateSort('up', '${goods.id}','${page}','${categoryId}')"><i class="iconfont icon-top1"></i> 向上</a>
                                                </c:if>

                                                <c:if test="${index < page.totalCount}">
                                                    <a href="javascript:goodsUpdateSort('down', '${goods.id}','${page}','${categoryId}')"><i class="iconfont icon-down"></i> 向下</a>
                                                </c:if>
                                                <a href="${ctx}/mall/showtemplategoods/showgoodform.do?id=${goods.id}&templateId=${templateId}&categoryId=${categoryId}">
                                                    <i class="iconfont icon-edit btn-icon"></i> 编辑</a>
                                                <a href="javascript:txz.deleteObject('确定要删除该商品？','${ctx}/mall/showgoods/delete.do?id=${goods.id}')">
                                                    <i class="iconfont icon-delete btn-icon"></i> 删除
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </c:if>
                        </li>
                    </c:forEach>
                </ul>
            </div>
            <div id="page_content" class="page-container"></div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">

    $(function () {
        //加载分页
        loadPageNew({elem: 'page_content', totalCount: '${page.totalCount}', limit: '${page.limit}', page: '${page.page}'});
        // 二维码弹窗显示/隐藏
        qrCodeDialog('.c-time-list-content', 'qr-btn', '.detail-content', '.bmDialog');

        layui.use(['laydate'], function () {
            var laydate = layui.laydate;
            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);
        });
        layui.use(['laytpl', 'laypage', 'element'], function () {
            laytpl = layui.laytpl;
            laypage = layui.laypage;
            element = layui.element;

        });

    })
    /**
     * 商品向上向下排序
     * @param op 操作
     */
    function goodsUpdateSort(op, goodsId,page,categoryId) {
        //loading层
        var loadIndex = layer.load(1, {
            shade: [0.1, '#fff'] //0.1透明度的白色背景
        });
        $.post("${ctx}/mall/showgoods/upDownUpdateSort.do", {
            goodsId : goodsId,
            type : op,
            page : page,
            categoryId : categoryId
        }, function (res) {
            layer.close(loadIndex);
            if (res.success) {
                location.reload();
            } else {
                /*layer.msg("更新排序异常");*/
            }
        })

    }
</script>
<script type="text/javascript">
    txz.initHeader({
        <c:if test="${!empty subjectId}">
        nav:[{
            name: '导购主题',
            href:'${ctx}/mall/showsubject/list.do'
        },{
            name: '类型管理',
            href: '${ctx}/mall/showcategory/list.do?subjectId=${subjectId}'
        },{
            name: '商品导购',
            curr: true
        }],
        info:'<span class="f12">共<b id="totalCount">${page.totalCount}</b>条记录</span>',
        btns:[{
            name: '发布商品',
            icon: 'add',
            href: '${ctx}/mall/showgoods/showgoodform.do?subjectId=${subjectId}&categoryId=${categoryId}'
        },{
            name: '返回',
            icon: 'back',
            href: '${ctx}/mall/showcategory/list.do?subjectId=${subjectId}'
        }]
        </c:if>
        <c:if test="${!empty templateId}">
        nav:[{
            name: '主题分类',
            href:'${ctx}/mall/showtemplate/list.do'
        },{
            name: '类型管理',
            href: '${ctx}/mall/showtemplatecategory/list.do?templateId=${templateId}'
        },{
            name: '商品导购',
            curr: true
        }],
        info:'<span class="f12">共<b id="totalCount">${page.totalCount}</b>条记录</span>',
        btns:[{
            name: '发布商品',
            icon: 'add',
            href: '${ctx}/mall/showtemplategoods/showgoodform.do?templateId=${templateId}&categoryId=${categoryId}'
        },{
            name: '返回',
            icon: 'back',
            href: '${ctx}/mall/showtemplatecategory/list.do?templateId=${templateId}'
        }]
        </c:if>
    });
</script>
</body>
</html>